package com.guocloud.medimind.config;

import com.guocloud.medimind.adviser.MyLoggerAdvisor;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@RequiredArgsConstructor
public class SpringAIConfig {

    /**
     * 显式使用 dashscopeChatModel 构造 ChatClient
     */
    @Bean
    public ChatClient chatClient(@Qualifier("dashscopeChatModel") ChatModel dashscopeChatModel, Advisor loggerAdvisor) {
        // 直接通过 ChatClient.builder(ChatModel) 指定模型
        return ChatClient
                .builder(dashscopeChatModel)    // ← 指定 dashscopeChatModel
                .defaultAdvisors(loggerAdvisor) // 添加 Advisor
                .build();
    }

    /**
     * 日志记录器
     */
    @Bean
    public Advisor loggerAdvisor() {
        return new MyLoggerAdvisor();
    }
}
